import pygame

"""
系统参数
"""
# 屏幕宽度
SCREEN_WIDTH = 480
# 屏幕高度
SCREEN_HIGHT = 700
# 帧率
FRAME = 120

# 英雄默认位置
HERO_PLACE_X_INIT = 50
HERO_PLACE_Y_INIT = 500
# 英雄宽高
HERO_PLACE_WIDTH_INIT = 102
HERO_PLACE_HIGHT_INIT = 126

"""
图片地址区
方便后续改配置方案
"""
# 图片背景地址
BACKGROUND_IMAGE = "./images/background.png"
# 英雄飞机
HERO_IMAGE_1 = "./images/me1.png"
HERO_IMAGE_2 = "./images/me2.png"

ENEMY_IMAGE_1 = "./images/enemy1.png"
ENEMY_IMAGE_2 = "./images/enemy2.png"

ENEMY_CRASH_IMAGE_1 = "./images/enemy1_down{}.png"
ENEMY_CRASH_IMAGE_2 = "./images/enemy2_down{}.png"
HERO_CRASH_IMAGE = "./images/me_destroy_{}.png"

# 初始化
pygame.init()

# 创建屏幕
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HIGHT))
# 加载背景
background = pygame.image.load(BACKGROUND_IMAGE)
# 绘制图像【blit：位块传输】
screen.blit(background, (0, 0))

# 加载英雄图片
hero = pygame.image.load(HERO_IMAGE_1)
# 绘制图像【blit：位块传输】
screen.blit(hero, (HERO_PLACE_X_INIT, HERO_PLACE_Y_INIT))

# 英雄矩形
hero_rect = pygame.Rect(HERO_PLACE_X_INIT, HERO_PLACE_Y_INIT, HERO_PLACE_WIDTH_INIT, HERO_PLACE_HIGHT_INIT)

# pygame.image.tostring(hero, 'RGB')

# 更新屏幕显示
pygame.display.update()

# 创建时钟周期类
clock = pygame.time.Clock()

while True:
    # 设置时钟
    clock.tick(FRAME)
    # clock.tick(1)

    # 重新绘画背景
    # screen.blit(background, (0, 0))

    # 获取相关操作事件
    # 鼠标移动  失去/获得焦点
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            print("用户退出")
            pygame.quit()
            exit(1)
        print(event.type)
        print(event)

    # 英雄位置
    # hero_rect.y -= 1
    # if hero_rect.y <= -HERO_PLACE_HIGHT_INIT:
    #     hero_rect.y = SCREEN_HIGHT
    # screen.blit(hero, hero_rect)

    # pygame.display.update()
    pass

# 卸载所有模块  ==》 不等于退出程序
# pygame.quit()
